import Mock from 'mockjs';
import zutil from '@/util/util'

Mock.setup({
  timeout: '500-1000'
})

const w_sex = ['男', '女'];

const zrangeDate = function(date, inter=1) {
	return new Date(new Date(date).getTime() + 3600 * 1000 * 24 * inter).formatDD("yyyy-MM-DD");
}

// 获取 mock.Random 对象
const Random = Mock.Random;
// mock一组数据
const test = function() {
  let articles = [];
  for (let i = 0; i < 10; i++) {
    let newArticleObject = {
      title: Random.csentence(5, 30), //  Random.csentence( min, max )
      thumbnail_pic_s: Random.dataImage('300x250', 'mock的图片'), // Random.dataImage( size, text ) 生成一段随机的 Base64 图片编码
      author_name: Random.cname(), // Random.cname() 随机生成一个常见的中文姓名
      date: Random.date() + ' ' + Random.time() // Random.date()指示生成的日期字符串的格式,默认为yyyy-MM-dd；Random.time() 返回一个随机的时间字符串
    }
    articles.push(newArticleObject)
  }

  return {
  	code: '0000',
    articles: articles
  }
}

const zloginInfo = function(param) {
	console.log(param);
	let attr = {
		id: Random.id(),
	  name: Random.cname(),
	  userid: Random.increment(100),
	  phone: Mock.mock(/^1[385][1-9]\d{8}/),
	  token: Random.word(15, 20)
	}
	return {
		code: '0000',
		msg: '',
		data: attr
	};
}

const zmodKeshiMult = function(param) {
	console.log(param);
	return {
		code: '0000',
		msg: '',
		data: {}
	};
}

const zjsSdk = function(param) {
	console.log(param);
	return {
		code: '0000',
		msg: '',
		data: {
			appId: Random.word(5, 10),
			timestamp: Random.word(5, 10),
			nonceStr: Random.word(5, 10),
			signature: Random.word(5, 10),
		}
	};
}

const zshortageList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      code: Random.string('number', 5),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      place: Random.county(true),
      date: Random.date('yyyy-MM-dd'),
      stock: Random.integer(200, 1000),
      ordernum: Random.integer(200, 1000),
      pay: Random.boolean(),
      result: Random.cword(2, 5),
      arrivaldate: Random.date('yyyy-MM-dd')
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zhospitalList = function(param) {
	console.log(param);
	let arr = [];
  const len = Random.integer(1, 10);
  for (let i = 0; i < 20; i++) {
  	let attr = {
  		value: Random.string('number', 5),
  		label: Random.cword(2, 5)
  	}
  	arr.push(attr)
  }
  
  return {
  	code: '0000',
    data: {
  		total: 20,
  		list: arr
  	}
  }
}

const zfeedbacksub = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zfeedbackList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      code: Random.string('number', 5),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      place: Random.county(true),
      hospital: Random.cword(2, 5),
      num: Random.integer(200, 1000),
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zfavoritesList = function(param) {
	console.log(param);
	let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
  	let attr = {
  		id: Random.id(),
  		code: Random.string('number', 5),
  		specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
  		place: Random.county(true),
  		hospital: Random.cword(2, 5),
  		date: Random.date('yyyy-MM-dd'),
  	}
  	arr.push(attr)
  }
  
  return {
  	code: '0000',
    data: {
  		total: 20,
  		list: arr
  	}
  }
}

const zfavoritesAdd = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zInventoryList = function(param) {
  console.log(param);
  let arr = [];
  for (let j = 0; j < 5; j++) {
    let attr = {
      id: Random.id(),
      name: '药品'+Random.integer(11, 20),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      factory: Random.cword(2, 5),
      num: Random.integer(200, 1000),
      price: Random.integer(1000, 10000),
      code: Random.string('number', 8),
      drugStorage: '药库'+Random.cword(2, 5),
      unit: '盒',
      org: '组织'+Random.cword(2, 5),
      buyer: Random.cname(2, 3),
    }
    arr.push(attr);
  }
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zCustomerList = function(param) {
  console.log(param);
  let arr = [];
  for (let j = 0; j < 10; j++) {
    let attr = {
      id: Random.id(),
      name: '客户'+Random.cname(2, 5),
    }
    arr.push(attr);
  }
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zOrderList = function(param) {
  console.log(param);
  let arr = [];
  for (let j = 0; j < 5; j++) {
    let attr = {
      id: Random.id(),
      type: '销售出库',
      hospital: '医院'+Random.cword(2, 5),
      price: Random.integer(1000, 10000),
    }
    arr.push(attr);
  }
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zOrderDetail = function(param) {
  console.log(param);
  let arr = [];
  let len = Random.integer(1, 5);
  for (let i = 0; i < len; i++) {
    let attr = {
      id: Random.id(),
      name: '药品'+Random.integer(11, 20),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      factory: Random.cword(2, 5),
      num: Random.integer(200, 1000),
      price: Random.integer(1000, 10000),
      code: Random.string('number', 8),
      drugStorage: '药库'+Random.cword(2, 5),
      unit: '盒',
      org: '组织'+Random.cword(2, 5),
      buyer: Random.cname(2, 3),
    }
    arr.push(attr);
  }
  return {
    code: '0000',
    data: {
      list: arr
    }
  }
}

const zOrderPicture = function(param) {
  console.log(param);
  let arr = [];
  let len = Random.integer(1, 5);
  for (let i = 0; i < len; i++) {
    let img = Random.dataImage('300x250', 'mock的图片');
    arr.push(img);
  }
  return {
    code: '0000',
    data:  arr
  }
}

const zprofitList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    const len2 = Random.integer(1, 3);
    let arr2 = [];
    for (let j = 0; j < len2; j++) {
      let temp = {
        name: Random.city(),
        value: Random.float(10, 100).toFixed(1)+'%'
      }
      arr2.push(temp);
    }

    let attr = {
      id: Random.id(),
      code: Random.string('number', 5),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      place: Random.county(true),
      date: Random.date('yyyy-MM-dd'),
      stock: Random.integer(200, 1000),
      ordernum: Random.integer(200, 1000),
      pay: Random.boolean(),
      result: Random.cword(2, 5),
      arrivaldate: Random.date('yyyy-MM-dd'),
      area: arr2
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zprofitfeedbacksub = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zprofitfeedbackList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      code: Random.string('number', 5),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      place: Random.county(true),
      hospital: Random.cword(2, 5),
      num: Random.integer(200, 1000),
      date: Random.date('yyyy-MM-dd'),
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zunmarketableList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      code: Random.string('number', 5),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      place: Random.county(true),
      date: Random.date('yyyy-MM-dd'),
      stock: Random.integer(200, 1000),
      days: Random.integer(10, 200),
      valdate: Random.date('yyyy-MM-dd'),
      type: Random.integer(0, 1)
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zunmarketablefeedbacksub = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zunmarketablefeedbackList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      code: Random.string('number', 5),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      place: Random.county(true),
      hospital: Random.cword(2, 5),
      num: Random.integer(200, 1000),
      date: Random.date('yyyy-MM-dd'),
      type: Random.integer(0, 1)
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zsvcList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      name: '药品'+Random.integer(11, 20),
      code: Random.string('number', 5),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      place: Random.county(true),
      date: Random.date('yyyy-MM-dd'),
      num: Random.integer(200, 1000),
      price: Random.integer(1000, 10000),
      profit: Random.integer(200, 1000),
      profitprice: Random.integer(1000, 3000),
      profitstand: Random.integer(200, 1000),
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zsvcstandList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      name: '药品'+Random.integer(11, 20),
      code: Random.string('number', 5),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      place: Random.county(true),
      date: Random.date('yyyy-MM-dd'),
      num: Random.integer(200, 1000),
      price: Random.integer(1000, 10000),
      profit: Random.integer(200, 1000),
      profitprice: Random.integer(1000, 3000),
      profitstand: Random.integer(200, 1000),
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const tagsArr = [
  {
    type: 1,
    name: '高毛利'
  },{
    type: 2,
    name: '高提成'
  },{
    type: 3,
    name: '好项目'
  },{
    type: 4,
    name: '政治任务'
  },{
    type: 5,
    name: '其他'
  },
]
const videoUrlArr = ['https://www.w3school.com.cn/i/movie.mp4', 'http://vfx.mtime.cn/Video/2019/02/04/mp4/190204084208765161.mp4']

const zProjectList = function(param) {
  console.log(param);
  let arr = [];
  for (let j = 0; j < 10; j++) {
    var tags = [];
    for (let i = 0; i < Random.integer(0, 5); i++) {
      let _temp = tagsArr[Random.integer(0, tagsArr.length-1)];
      tags.push(_temp);
    }

    let attr = {
      id: Random.id(),
      name: '项目'+Random.cword(2, 5),
      tags: tags,
      videoUrl: videoUrlArr[Random.integer(0, videoUrlArr.length-1)],
      status: Random.integer(0, 3)
    }
    arr.push(attr);
  }
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zProjectInfo = function(param) {
  console.log(param);
  let arr = [];
  let len = Random.integer(1, 5);
  for (let i = 0; i < len; i++) {
    let attr = {
      id: Random.id(),
      depart: Random.cword(4, 10),
      total: Random.integer(10, 50),
      second: Random.integer(0, 10),
      first: Random.integer(1, 20),
      billingRate: Random.float(10, 100).toFixed(1)+'%',
      succRate: Random.float(10, 100).toFixed(1)+'%'
    }
    arr.push(attr);
  }
  let totalize = {
    total: Random.integer(10, 50),
    second: Random.integer(0, 10),
    first: Random.integer(1, 20),
    billingRate: Random.float(10, 100).toFixed(1)+'%',
    succRate: Random.float(10, 100).toFixed(1)+'%'
  }
  return {
    code: '0000',
    data: {
      list: arr,
      summary: Random.cword(50, 300),
      totalize: totalize
    }
  }
}

const zProjectdetail = function(param) {
  console.log(param);
  let arr = [];
  let len = Random.integer(1, 10);
  for (let i = 0; i < len; i++) {
    var imgList = [];
    for (let j=0; j<Random.integer(0, 5); j++){
      let _temp = {
        url: Random.dataImage('300x250', 'mock的图片'),
        id: Random.increment(10000)
      }
      imgList.push(_temp)
    }
    let attr = {
      id: Random.id(),
      periods: Random.increment(1)+'期',
      code: Random.integer(10, 50),
      hospital: Random.cword(2, 5),
      contacts: Random.cname(2, 5),
      contactsNo: Mock.mock(/^1[385][1-9]\d{8}/),
      wuliaocode: Random.integer(10, 50),
      wuliaoname: Random.cword(2, 5),
      specifications: Random.float(0.1, 1).toFixed(1)+'mg X '+Random.integer(5, 10).toFixed(1)+'ml',
      area: Random.city(),
      firstdate: Random.date('yyyy-MM-dd'),
      firstnum: Random.integer(1, 20),
      seconddate: Random.date('yyyy-MM-dd'),
      secondnum: Random.integer(1, 20),
      status: Random.integer(0, 2),
      imgList: imgList
    }
    arr.push(attr);
  }
  return {
    code: '0000',
    data: {
      list: arr
    }
  }
}

const zNewList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      hospital: Random.cword(2, 5),
      code: Random.string('number', 5),
      name: Random.cword(2, 5),
      lastMonthSale: Random.integer(2000, 10000),
      thrAvgSale: Random.integer(200, 1000),
      lastThrSale: Random.integer(200, 1000),
      stock: Random.integer(200, 1000),
      salenum: Random.integer(200, 1000),
      startdate: Random.date('MM-dd'),
      enddate: Random.date('MM-dd'),
      states: Random.integer(0, 1)
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zNewListSend = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zHistoryList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 20; i++) {
    let attr = {
      id: Random.id(),
      hospital: Random.cword(2, 5),
      code: Random.string('number', 5),
      name: Random.cword(2, 5),
      lastMonthForecast: Random.integer(2000, 10000),
      lastMonthActual: Random.integer(2000, 10000),
      accuracy: Random.float(10, 100).toFixed(1)+'%',
      accuracyS: Random.float(10, 100).toFixed(1)+'%',
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr,
      lastMonthForecastTotal: Random.integer(2000, 10000),
      lastMonthActualTotal: Random.integer(2000, 10000),
      accuracyTotal: Random.float(10, 100).toFixed(1)+'%',
      accuracySTotal: Random.float(10, 100).toFixed(1)+'%',
    }
  }
}

const zSaleSubList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      hospital: Random.cword(2, 5),
      code: Random.string('number', 5),
      name: Random.cword(2, 5),
      estimatedNum: Random.integer(2000, 10000),
      date: Random.date('yyyy-MM-dd'),
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zProjectListRec = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zProjectdetailRec = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zCommunicateList = function(param) {
  console.log(param);
  let arr = [];
  const len = Random.integer(0, 10);
  for (let i = 0; i < 10; i++) {
    let attr = {
      id: Random.id(),
      name: Random.cword(5),
      dept: Random.cword(5),
      category: Random.cword(5),
      sdate: Random.date('yyyy-MM-dd'),
      donedate: Random.date('yyyy-MM-dd'),
      status: Random.integer(0, 5),
      level: Random.integer(0, 2),
      lastStatus: Random.integer(0, 5)
    }
    arr.push(attr)
  }
  
  return {
    code: '0000',
    data: {
      total: 20,
      list: arr
    }
  }
}

const zCommunicateSub = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zCommunicateAdd = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zCommunicateMember = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

const zCommunicateCancel = function(param) {
  console.log(param);
  return {
    code: '0000',
    msg: '',
    data: {}
  };
}

// Mock.mock( url, post/get , 返回的数据);
/**
 * 带参数的get方法只能使用正则去匹配
 * /api/zsingle/10001?channel=1&check_date=1564984632167
**/
Mock.mock('/api/zloginInfo', 'post', zloginInfo);
Mock.mock('/api/zmodKeshiMult', 'post', zmodKeshiMult);
Mock.mock('/api/zjsSdk', 'post', zjsSdk);
Mock.mock('/api/zshortageList', 'post', zshortageList);
Mock.mock('/api/zhospitalList', 'post', zhospitalList);
Mock.mock('/api/zfeedbacksub', 'post', zfeedbacksub);
Mock.mock('/api/zfeedbackList', 'post', zfeedbackList);
Mock.mock('/api/zfavoritesList', 'post', zfavoritesList);
Mock.mock('/api/zfavoritesAdd', 'post', zfavoritesAdd);
Mock.mock('/api/zInventoryList', 'post', zInventoryList);
Mock.mock('/api/zCustomerList', 'post', zCustomerList);
Mock.mock('/api/zOrderList', 'post', zOrderList);
Mock.mock('/api/zOrderDetail', 'post', zOrderDetail);
Mock.mock('/api/zOrderPicture', 'post', zOrderPicture);
Mock.mock('/api/zprofitList', 'post', zprofitList);
Mock.mock('/api/zprofitfeedbacksub', 'post', zprofitfeedbacksub);
Mock.mock('/api/zprofitfeedbackList', 'post', zprofitfeedbackList);
Mock.mock('/api/zunmarketableList', 'post', zunmarketableList);
Mock.mock('/api/zunmarketablefeedbacksub', 'post', zunmarketablefeedbacksub);
Mock.mock('/api/zunmarketablefeedbackList', 'post', zunmarketablefeedbackList);
Mock.mock('/api/zsvcList', 'post', zsvcList);
Mock.mock('/api/zsvcstandList', 'post', zsvcstandList);
Mock.mock('/api/zProjectList', 'post', zProjectList);
Mock.mock('/api/zProjectInfo', 'post', zProjectInfo);
Mock.mock('/api/zProjectdetail', 'post', zProjectdetail);
Mock.mock('/api/zNewList', 'post', zNewList);
Mock.mock('/api/zNewListSend', 'post', zNewListSend);
Mock.mock('/api/zHistoryList', 'post', zHistoryList);
Mock.mock('/api/zSaleSubList', 'post', zSaleSubList);
Mock.mock('/api/zProjectListRec', 'post', zProjectListRec);
Mock.mock('/api/zProjectdetailRec', 'post', zProjectdetailRec);
Mock.mock('/api/zCommunicateList', 'post', zCommunicateList);
Mock.mock('/api/zCommunicateSub', 'post', zCommunicateSub);
Mock.mock('/api/zCommunicateAdd', 'post', zCommunicateAdd);
Mock.mock('/api/zCommunicateMember', 'post', zCommunicateMember);
Mock.mock('/api/zCommunicateCancel', 'post', zCommunicateCancel);

export default Mock;
